
#include "s_controller.h"
#include "s_room.h"
#include "classdef.h"


rsp_s_settings  RSPS_SETTINGS;



////////////////////////////////////////////////////////////////////////////////
rsp_s_object_state* rsp_s_object_state::get_from_ptr( rsp_base* p )
{
    DASSERT( Gactive_controller->room_controller() );
    return ((rsp_s_room_controller*)Gactive_controller)->view_find(p);
}

/*
////////////////////////////////////////////////////////////////////////////////
void rsp_s_object_state::ack_state( ushort stateid )
{
    if( int(stateid - _ref._state) <= 0 )   //discard old acks
        return;

    //this should not happen, something weird with the client
    if( int(stateid - _statecache[_last]._state) > 0 )
        return;

    //acked the last state
    if( stateid == _statecache[_last]._state )
    {
        swap_ref(_last);
        return;
    }

    uint msk = _ref._mask;

    //find the first state that is newer _and_ has a different mask
    uint i, n = _count;
    for( i=(_last+1-_count)&xCACHE_SIZE; n>0; i=(i+1)&xCACHE_SIZE, --n )
    {
        if( int(stateid - _statecache[i]._state) < 0  &&  msk == _statecache[i]._mask )
            break;
        msk = _statecache[i]._mask;
    }

    //
    if( n == _count )       //repetitive ack of the reference state, ignore
    {
        
    }
    else if( n > 0 )        //not the last state, and not the reference state either
    {
        //get the previous state
        uint k = (_last - n) & xCACHE_SIZE;
        swap_ref(k);
    }
    else    //n == 0   =>   a nonexistent state can be the new reference
    {
        //we can be out of the buffer only for two reasons:
        // - either the _last state is the stateid
        // - or the states consequent to the stateid have the same mask
        // in the first case, we swap the _last state for ref (this is handled already above)
        // in the second case we must swap the state that precedes the last one,
        // because otherwise the terminal won't get updates
        
        //this test isn't necessary because this condition occurs only
        // when the buffer overflows
        //if( _count > 1 )
        
        swap_ref( (_last - 1) & xCACHE_SIZE );
    }
}
*/
